/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegistrarIndividual.java
 *
 * Created on Jul 15, 2009, 4:54:34 PM
 */

package gui.tabbedpane;
import delegate.GestionDelegate;
import controlacciones.ejb3.entity.TbDatosCliente;
import gui.JP_RegistrarAccion_Notificacion;
import gui.JP_RegistrarAccion_Ocurrencia;
import helper.JP_Modelo;
import helper.Utiles_MensajesDialogo;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
/**
 *
 * 
 */
public class JP_DatosCliente extends JP_Modelo {

    /** Creates new form RegistrarIndividual */
    public JP_DatosCliente() {
        inicializaComponentes();

    }

    private void inicializaComponentes(){
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jp_DatosCliente = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtNroInscripcion = new javax.swing.JFormattedTextField();
        txtNombre = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        txtCodigoCatastral = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtNroSolicitud = new javax.swing.JTextField();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_DatosCliente.class);
        jp_DatosCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_DatosCliente.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jp_DatosCliente.border.titleFont"))); // NOI18N
        jp_DatosCliente.setName("jp_DatosCliente"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        txtNroInscripcion.setName("txtNroInscripcion"); // NOI18N
        txtNroInscripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNroInscripcionKeyPressed(evt);
            }
        });

        txtNombre.setName("txtNombre"); // NOI18N
        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombreKeyPressed(evt);
            }
        });

        txtDireccion.setName("txtDireccion"); // NOI18N
        txtDireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDireccionActionPerformed(evt);
            }
        });

        txtCodigoCatastral.setName("txtCodigoCatastral"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        txtNroSolicitud.setName("txtNroSolicitud"); // NOI18N
        txtNroSolicitud.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNroSolicitudKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jp_DatosClienteLayout = new javax.swing.GroupLayout(jp_DatosCliente);
        jp_DatosCliente.setLayout(jp_DatosClienteLayout);
        jp_DatosClienteLayout.setHorizontalGroup(
            jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DatosClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNroSolicitud, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCodigoCatastral, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                    .addComponent(txtNroInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jp_DatosClienteLayout.setVerticalGroup(
            jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp_DatosClienteLayout.createSequentialGroup()
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNroInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtCodigoCatastral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtNroSolicitud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jp_DatosCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jp_DatosCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtNroSolicitudKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroSolicitudKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            if( ventana == 1 ){
                JP_RegistrarAccion_Ocurrencia pr = (JP_RegistrarAccion_Ocurrencia)this.getRefDep();
                pr.getJp_ope().getBtnGuardar().requestFocus();
            }
            if( ventana == 3 ){
                JP_RegistrarAccion_Notificacion pr = (JP_RegistrarAccion_Notificacion)this.getRefDep();
                pr.getJp_ope().getBtnGuardar().requestFocus();
            }
        }
    }//GEN-LAST:event_txtNroSolicitudKeyPressed

    private void txtNombreKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.txtDireccion.requestFocus();
        }
    }//GEN-LAST:event_txtNombreKeyPressed

    private void txtDireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDireccionActionPerformed
       
            if( ventana == 1 ){
                JP_RegistrarAccion_Ocurrencia pr = (JP_RegistrarAccion_Ocurrencia)this.getRefDep();
                pr.getJp_ope().getBtnGuardar().requestFocus();
            }
            if( ventana == 3 ){
               this.txtNroSolicitud.requestFocus();
            }
       
    }//GEN-LAST:event_txtDireccionActionPerformed

    private void txtNroInscripcionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroInscripcionKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            buscarCliente();
        }
    }//GEN-LAST:event_txtNroInscripcionKeyPressed

    public void buscarCliente(){
        // TODO add your handling code here:
        String numInscrip = this.txtNroInscripcion.getText().trim();
        tbDatosCliente = null;
        if( numInscrip.trim().equalsIgnoreCase("") ){
            System.out.println( "Cliente nulo" );
            this.txtNroInscripcion.setText("");            
            this.txtNombre.requestFocus();
        }else{            
            try {
                tbDatosCliente = GestionDelegate.getInstance().getDatosCliente(numInscrip);
            } catch (Exception ex) {
//                Logger.getLogger(JP_ClienteMasivo.class.getName()).log(Level.SEVERE, null, ex);
                return;
            }
            if( tbDatosCliente == null ){ //Si no encuentra el usuario
                Utiles_MensajesDialogo.mensajeAlerta("El cliente no se encuentra registrado");
                int codTipoAccion = 0;
                if( ventana == 1 ){
                    JP_RegistrarAccion_Ocurrencia pr = (JP_RegistrarAccion_Ocurrencia)this.getRefDep();
                    codTipoAccion = pr.getCodTipoAccion();
                }
                if( ventana == 3 ){
                    codTipoAccion = 1141;
                }
                 
                 if( codTipoAccion == 918 || codTipoAccion == 919 || codTipoAccion == 1140 || codTipoAccion == 1141 ){
                     this.txtNombre.requestFocus();
                 }else{
                     this.txtNroInscripcion.setText("");
                     this.requestFocus();
                     this.txtNroInscripcion.setCaretPosition(0);
                 }
            }else{
                this.txtNombre.setText(tbDatosCliente.getNombre());
                this.txtDireccion.setText(tbDatosCliente.getDireccion());
                this.txtCodigoCatastral.setText(tbDatosCliente.getZona()+ "." + tbDatosCliente.getRegion() + "." + tbDatosCliente.getSector() + "." +
                            tbDatosCliente.getMzn() + "." + tbDatosCliente.getLote() + "." + tbDatosCliente.getSublote());
                this.txtNroSolicitud.requestFocus();
            }
        }
    }

    public void limpiar(){
        this.txtCodigoCatastral.setText("");
        this.txtDireccion.setText("");
        this.txtNombre.setText("");
        this.txtNroInscripcion.setText("");
        this.txtNroSolicitud.setText("");
    }

    public void habilitarComoponentes( boolean ban ){
        this.txtCodigoCatastral.setEnabled(ban);
        this.txtDireccion.setEnabled(ban);
        this.txtNombre.setEnabled(ban);
        this.txtNroInscripcion.setEnabled(ban);
        this.txtNroSolicitud.setEnabled(ban);
    }

    public TbDatosCliente getTbDatosCliente() {
        return tbDatosCliente;
    }

    public JTextField getTxtCodigoCatastral() {
        return txtCodigoCatastral;
    }

    public JTextField getTxtDireccion() {
        return txtDireccion;
    }

    public JTextField getTxtNombre() {
        return txtNombre;
    }

    public JTextField getTxtNroSolicitud() {
        return txtNroSolicitud;
    }

    public JFormattedTextField getTxtNroInscripcion() {
        return txtNroInscripcion;
    }

    public int getVentana() {
        return ventana;
    }

    public void setVentana(int ventana) {
        this.ventana = ventana;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jp_DatosCliente;
    private javax.swing.JTextField txtCodigoCatastral;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JFormattedTextField txtNroInscripcion;
    private javax.swing.JTextField txtNroSolicitud;
    // End of variables declaration//GEN-END:variables
    private controlacciones.ejb3.entity.TbDatosCliente tbDatosCliente;
    int ventana = -1;
}
